package ntu.metaweb.service;

import rice.Continuation;
import rice.p2p.commonapi.Id;
import ntu.metaweb.Metaweb;
import ntu.metaweb.storage.PagesWithTag;
import ntu.metaweb.storage.PagesWithTagKey;
import ntu.metaweb.storage.WebPage;
import ntu.metaweb.storage.WebPageQuery;
import ntu.metaweb.update.NewTag;

public class Service {

	public static void insertWebPage(WebPage webpage) {
		Metaweb.getInstance().getDhtApplication().insert(webpage, 
				new Continuation<Boolean[], Exception>() {

					@Override
					public void receiveException(Exception exception) {
						// TODO Auto-generated method stub
						
					}

					@Override
					public void receiveResult(Boolean[] result) {
						// TODO Auto-generated method stub
						
					}
		});
	}
	
	public static void insertWebPageQuery(WebPageQuery query) {
		Metaweb.getInstance().getDhtApplication().insert(query, 
				new Continuation<Boolean[], Exception>() {

					@Override
					public void receiveException(Exception exception) {
						// TODO Auto-generated method stub
						
					}

					@Override
					public void receiveResult(Boolean[] result) {
						// TODO Auto-generated method stub
						
					}
		});
	}
	
	public static void insertPagesWithTag(String tag) {
		PagesWithTag pageswithtag = new PagesWithTag(
				new PagesWithTagKey(tag), tag);
		Metaweb.getInstance().getDhtApplication().insert(pageswithtag,
				new Continuation<Boolean[], Exception>() {
			@Override
			public void receiveException(Exception exception) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void receiveResult(Boolean[] result) {
				// TODO Auto-generated method stub
				
			}
		});
	}

	public static void insertPagesWithTag(String tag, NewTag... newTag) {
		PagesWithTag pageswithtag = new PagesWithTag(
				new PagesWithTagKey(tag), tag);
		for (NewTag temp : newTag) {
			pageswithtag.addPage(temp.url, temp.tagger, temp.title, temp.pageRating);
		}
		Metaweb.getInstance().getDhtApplication().insert(pageswithtag,
				new Continuation<Boolean[], Exception>() {
			@Override
			public void receiveException(Exception exception) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void receiveResult(Boolean[] result) {
				// TODO Auto-generated method stub
				
			}
		});
	}
}
